package main

import (
	"common"
	"common/configx"
	"common/databasex"
	"common/zapx"
	"flag"
	"go.uber.org/zap"
	"models/dal/model"
)

var config_path = flag.String("config_path", "./config.yaml", "配置文件位置")

func main() {
	flag.Parse()
	if err := common.Init(
		*config_path,
		common.WithBootstrapInit(func(config configx.Config) any {
			return zapx.WithAppName(config.App.Name)
		}),
		common.WithBootstrapInit(func(config configx.Config) any {
			return databasex.WithMysqlDns(config.Mysql.Dns)
		}),
	); err != nil {
		panic(err)
	}

	bt := common.NewBootstrap()
	if err := bt.Boot(); err != nil {
		zapx.Logger.Error("应到程序启动失败", zap.Error(err))
		return
	}
	defer func() {
		bt.Shutdown()
	}()

	err := databasex.M.DB.AutoMigrate(
		&model.FaUser{},
		&model.FaEmailVerify{},
	)
	if err != nil {
		zapx.Logger.Error("迁移失败", zap.Error(err))
		return
	}
}
